﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Macds.Core.ServiceLocator
{
    public class Locator
    {
        private object service;
        private LocatorTarget target;

        public Locator(LocatorTarget target)
        {
            this.target = target;
        }

        public Locator()
        {
            this.target = LocatorEnvironment.Target;
        }

        public object Service
        {
            get
            {
                if (service == null)
                    this.service = this.target.LoadObject();

                return service;
            }
        }
    }

    public class Locator<T> where T : class
    {
        private Locator locator;

        public Locator(LocatorTarget target)
        {
            this.locator = new Locator(target);
        }

        public Locator()
        {
            this.locator = new Locator();
        }

        public T Service
        {
            get
            {
                return (T)this.locator.Service;
            }
        }
    }
}
